#region License
// ValidationMessageHelper.cs
// 
// Copyright (c) 2012 Xoqal.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
// http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#endregion

namespace Shammateh.Entities
{
    using System.Text;

    /// <summary>
    /// Helps to create proper messages for validations.
    /// </summary>
    public class ValidationMessageHelper
    {
        /// <summary>
        /// Gets the required message.
        /// </summary>
        /// <param name="fieldName">Name of the field.</param>
        public static string GetRequiredMessage(string fieldName)
        {
            return string.Format(Resources.Resource.RequiredFieldMessage, fieldName);
        }

        /// <summary>
        /// Gets the incorrect format message.
        /// </summary>
        /// <param name="fieldName">Name of the field.</param>
        /// <returns></returns>
        public static string GetIncorectFormatMessage(string fieldName)
        {
            return string.Format(Resources.Resource.IncorectFormatMessage, fieldName);
        }

        /// <summary>
        /// Gets the invalid range message.
        /// </summary>
        /// <param name="fieldName">Name of the field.</param>
        /// <param name="min">The min value. If set to null it will ignored and the message will be created correctly.</param>
        /// <param name="max">The max value. If set to null it will ignored and the message will be created correctly.</param>
        /// <returns></returns>
        public static string GetInvalidRangeMessage(string fieldName, decimal? min, decimal? max)
        {
            var sb = new StringBuilder();
            sb.AppendFormat(Resources.Resource.RangeFieldMessage, fieldName);
            if (min.HasValue)
            {
                sb.AppendFormat(Resources.Resource.RangeFieldBiggerThan, min.Value);
            }

            if (max.HasValue)
            {
                if (min.HasValue)
                {
                    sb.Append(Resources.Resource.And);
                }

                sb.AppendFormat(Resources.Resource.RangeFieldSmallerThan, max.Value);
            }
            else
            {
                sb.Append(".");
            }

            return sb.ToString();
        }
    }
}
